<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>

</template>
<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    // 防止长度为空是渲染，等有值时索引处于最后一项
    showSwiper () {
      return this.list.length
    }
  }
}
</script>
<!-- 受 scope影响，如果要 对子组件起作用 用 .a >>> .b 或 .a /deep/ .b (/deep/兼容更好) 官网说明地址： https://vue-loader.vuejs.org/zh/guide/scoped-css.html#%E6%B7%B1%E5%BA%A6%E4%BD%9C%E7%94%A8%E9%80%89%E6%8B%A9%E5%99%A8-->
<style scoped lang="stylus">
  // 深度作用选择器 >>> 或 /deep/
  .wrapper >>> .swiper-pagination-bullet-active
    background-color: #f00
  .wrapper
    overflow: hidden
    width: 100%
    height: 0
    padding-bottom: 26.66%
    background-color: #eee
    /deep/ .swiper-pagination-bullet-active
      background-color: #fff
  .swiper-img
    width: 100%
</style>
